Skip to content

Method: handleCall(CallableStatement, int)

1: package de.fhdw.wtf.persistence.utils;
2:
3: import java.math.BigDecimal;
4: import java.math.BigInteger;
5: import java.sql.CallableStatement;
6: import java.sql.SQLException;
7:
8: import de.fhdw.wtf.persistence.exception.NotValidInputException;
9: import de.fhdw.wtf.persistence.meta.IntegerValue;
10: import de.fhdw.wtf.persistence.meta.Object;
11:
12: /**
13: * Wrapper for a Integer for a Database-Query.
14: */
15: public class DBConnectionIntegerHandler implements DBConnectionObjectHandler {
16:         
17:         private final BigInteger integer;
18:         
19:         @Override
20:         public String getObjectTypeString() {
21:                 return "Int";
22:         }
23:         
24:         @Override
25:         public void handleCall(final CallableStatement call, final int parameterIndex) throws SQLException {
26:                 final BigDecimal wrapper = new BigDecimal(this.integer);
27:                 call.setBigDecimal(parameterIndex, wrapper);
28:         }
29:         
30:         @Override
31:         public Object getObject() {
32:                 return new IntegerValue(this.integer);
33:         }
34:         
35:         /**
36:          * creates a wrapper for a integer for a database connection.
37:          *
38:          * @param integer
39:          * the wrapped integer
40:          * @throws NotValidInputException
41:          * throws when the given integer is null
42:          */
43:         public DBConnectionIntegerHandler(final BigInteger integer) throws NotValidInputException {
44:                 super();
45:                 
46:                 if (integer == null) {
47:                         throw new NotValidInputException("integer");
48:                 }
49:                 
50:                 this.integer = integer;
51:         }
52: }